// =============================================================================
//  Spangles Analyzer
//
//  Copyright(c) 2008
//  See LICENSE.txt for licensing information.
// =============================================================================

package com.google.spangles.view.service.impl;

import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import com.google.spangles.domain.Color;
import com.google.spangles.domain.GameState;
import com.google.spangles.domain.Location;
import com.google.spangles.view.Visualization;
import com.google.spangles.view.service.VisualizationService;

/**
 * (Description)
 * (Any invariants [conditions that are always true] )
 * (Usage instructions, and/or examples)
 * (TODOs, ASSUMPTIONs, etc.)
 * (Known Bugs)
 * (Concurrency strategy - not thread safe or how it's thread safe)
 * 
 * @author Chris
 */
public class VisualizationServiceImpl implements VisualizationService
{

   /**
    * (Description - what the method does and why)
    * (Visibility decision, if not obvious)
    * (Pre/Post Conditions)
    * (Usage examples)
    * (Algorithmic notes)
    * (Concurrency issues)
    * @param gs
    * @return
    */
   public Visualization visualize(GameState gs)
   {
      Visualization v = new Visualization();
      
      // Add all the pieces
      Map<Location, Color> layout = gs.getLayout();
      for(Iterator<Entry<Location, Color>> ei = layout.entrySet().iterator(); ei.hasNext(); )
      {
         Entry<Location, Color> e = ei.next();
         Location l = e.getKey();
         Color c = e.getValue();
         int x = l.getX();
         int y = l.getY();
         boolean pu = (((x+y)&1)==0);
         v.record(l, c, pu);
      }
      
      // Add the aura
      Collection<Location> aura = gs.getValidMoves();
      for(Iterator<Location> li = aura.iterator(); li.hasNext(); )
      {
         Location l = li.next();
         int x = l.getX();
         int y = l.getY();
         boolean pu = (((x+y)&1)==0);
         v.record(l, null, pu);
      }      
      
      return v;
   }

}
